package ch.exm.storm.query;

import java.util.ArrayList;
import java.util.Collection;

import ch.exm.storm.conditions.Condition;
import ch.exm.storm.query.selection.EvaluatedSelection;
import ch.exm.storm.query.selection.Selection;

public abstract class AbstractQueryPlan implements QueryPlan {

	protected final Collection<?> applyConditions(Collection<?> list, Condition condtion) {
		if (condtion == null) return list;
		Collection<Object> result = new ArrayList<Object>();
		for (Object object : list) if (condtion.matches(object)) result.add(object);
		return result;
	}

	protected final Collection<?> applySelection(Collection<?> list, Selection selection) {
		return selection == null ? list : new EvaluatedSelection(selection).applySelectionOn(list);
	}
}
